package com.xidian.zhiancloud.controller.cgs.ExamManager;

import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.ExamType;
import com.xidian.zhiancloud.service.cgs.ExamManager.ExamTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 教育培训-试题类别表
 * @Author chenguosong
 * @Date 2020/11/26 0:28
 * @Mail 2581592671@qq.com
 */

@RestController
@RequestMapping("/ExamType")
public class ExamTypeController {
    @Autowired
    private ExamTypeService examTypeService;

    /**
     * 添加试题类别
     * @param examType 试题类别
     * @return 返回 试题类别 对象
     */
    @PostMapping("/add")
    public ResultDTO<Boolean> add(@RequestBody ExamType examType) {
        examTypeService.add(examType);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 删除试题类别
     * @param id 试题类别ID
     * @return 返回 试题类别 对象
     */
    @DeleteMapping("/{id}")
    public ResultDTO<Boolean> deleteById(@PathVariable Long id) {
        examTypeService.deletebyid(id);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    /**
     * 试题类别列表
     * @param current 偏移量
     * @param size 数量
     * @return 返回 试题类别 对象
     */
    @GetMapping("/getList")
    public ResultDTO<List<ExamType>> list(@RequestParam(value = "current", required = false, defaultValue = "0") int current,
                                          @RequestParam(value = "size", required = false, defaultValue = "10") int size) {
        return ResultDTO.successOf(examTypeService.getListPlan(current, size), GeneralResponseEnums.SUCCESS);
    }

    /**
     * 编辑试题类别
     * @param examType 试题类别
     * @return 返回 试题类别 对象
     */
    @PostMapping("/update")
    public ResultDTO<Boolean> update(@RequestBody ExamType examType) {
        examTypeService.update(examType);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }
}
